package com.example.qts;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.qts.adapter.VpFragmentadapter;
import com.example.qts.fragments.DishFragment;
import com.example.qts.fragments.HomeFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ViewPager mVp;
    private TabLayout mTab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    private void initViews() {
        mVp = findViewById(R.id.vp);
        mTab = findViewById(R.id.tab);
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new HomeFragment());
        fragments.add(new DishFragment());
        VpFragmentadapter vpFragmentadapter = new VpFragmentadapter(getSupportFragmentManager(), fragments);
        mVp.setAdapter(vpFragmentadapter);
        mTab.setupWithViewPager(mVp);
        mTab.getTabAt(0).setText("首页");
        mTab.getTabAt(1).setText("Dish");
    }
}
